package com.hanlyjiang.library.components.frag;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * App 包的基础Fragment 类
 *
 * @author hanlyjiang on 2017/6/15-14:55.
 * @version 1.0
 */

public abstract class BaseFragment extends Fragment implements IFragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (getLayoutResId() == 0) {
            return super.onCreateView(inflater, container, savedInstanceState);
        }
        return inflater.inflate(getLayoutResId(), container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initUI(getView(),getActivity());
    }

    /**
     * 查找 View
     *
     * @param viewId
     * @return
     */
    public View findViewById(int viewId) {
        if (getView() == null) {
            throw new RuntimeException("请为Fragment设置View 后再调用此方法");
        }
        return getView().findViewById(viewId);
    }

}
